import Vue from 'vue'
import Router from 'vue-router'

/* layout */
import Layout from 'views/layout/layout'

/* 荟购云电商平台 Router 配置 */
import myUserRouter from './pagesRoute/myUser'
import mallSettingRouter from './pagesRoute/mallSetting'
import mallGoodsRouter from './pagesRoute/mallGoods'
import mallTradingRouter from './pagesRoute/mallTrading'
import marketPromotionRouter from './pagesRoute/marketPromotion'
import accountingRouter from './pagesRoute/accounting'
import messageInteractRouter from './pagesRoute/messageInteract'
import otherOptionRouter from './pagesRoute/otherOption'

Vue.use(Router)

/** 注意: 子菜单只出现在 children.length>=1
 *  查看详情  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   如果 `hidden:true` 将不会显示在侧边栏中 ( 默认为 false )；
* alwaysShow: true               如果设置 `true`, 将始终显示根菜单, 无论是否有子路由；
*                                如果没有设置 `alwaysShow`, 只有一个以上的路由在 children下时，
*                                它将成为嵌套模式，否则不显示根菜单；
* redirect: noredirect           如何 `redirect:noredirect` 不会在面包屑中重定向；
* name:'router-name'             这个 name 用于 <keep-alive> (必须设置 !!!)；
* meta : {
    roles: ['admin','editor']    将控制页面角色 ( 您可以设置多个角色 )；
    title: 'title'               在子菜单和面包屑中显示的名称 (推荐设置)；
    icon: 'svg-name'             在侧边栏显示图标；
    noCache: true                如果为 true,页面将不会缓存 ( 默认为 false )；
  }
**/

export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('views/errorPage/401'),
    hidden: true
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    meta: {
      roles: ['demo', 'editor']
    },
    children: [{
      path: 'dashboard',
      component: () => import('pages/dashboard/index'),
      name: 'Dashboard',
      meta: {
        title: 'dashboard',
        icon: 'dashboard',
        noCache: true
      }
    }]
  },

  /** 当路由表太长时，可以将其拆分为小模块 **/
  // 以下小模块为 “荟购云电商平台” 所有路由
  myUserRouter,
  mallSettingRouter,
  mallGoodsRouter,
  mallTradingRouter,
  marketPromotionRouter,
  accountingRouter,
  messageInteractRouter,
  otherOptionRouter,
  // 以下小模块为 “应用组件” 所有路由
  {
    path: '/table',
    component: Layout,
    redirect: '/table/index',
    meta: {
      roles: ['editor']
    },
    children: [
      {
        path: 'index',
        component: () => import('views/table/index'),
        name: 'table',
        meta: {
          title: 'table',
          icon: 'table',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/documentation',
    component: Layout,
    redirect: '/documentation/index',
    meta: {
      roles: ['editor']
    },
    children: [
      {
        path: 'index',
        component: () => import('views/documentation/index'),
        name: 'Documentation',
        meta: {
          title: 'documentation',
          icon: 'documentation',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/guide',
    component: Layout,
    redirect: '/guide/index',
    meta: {
      roles: ['editor']
    },
    children: [
      {
        path: 'index',
        component: () => import('views/guide/index'),
        name: 'Guide',
        meta: {
          title: 'guide',
          icon: 'guide',
          noCache: true
        }
      }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    meta: {
      roles: ['demo']
    },
    children: [
      {
        path: 'https://gitee.com/',
        name: 'externalLink',
        meta: {
          title: 'externalLink',
          icon: 'link'
        }
      }
    ]
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]
